package main

import (
	"fmt"
	"io/ioutil"
	"os"
)

func judge() {
	const filename = "abc.txt"

	// 检查文件是否存在
	if _, err := os.Stat(filename); os.IsNotExist(err) {
		fmt.Printf("文件 '%s' 不存在。\n", filename)
		return
	}

	//方式一
	contents, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s\n", contents)
	}
	//方式2
	if contents, err := ioutil.ReadFile(filename); err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s\n", contents)
	}
}

func grade(score int) string {
	g := ""
	switch {
	case score < 0 || score > 100:
		panic(fmt.Sprint(
			"Wrong score: %d", score))
	case score < 60:
		g = "F"
	case score < 80:
		g = "C"
	case score < 90:
		g = "B"
	case score <= 100:
		g = "A"
	}
	return g
}

func main() {
	fmt.Println(
		//grade(0),    error
		grade(59),
		grade(60),
		grade(80),
		grade(90),
		grade(100),
		//grade(101),  error
	)

}
